package com.efounder.view.pop;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.efounder.chat.activity.MobileShareActivity;
import com.efounder.chat.activity.ShareToZoneActivity;
import com.efounder.chat.model.ShareContent;
import com.efounder.chat.struct.StructFactory;
import com.efounder.chat.view.CommonOtherPopWindow;
import com.efounder.frame.activity.EFTransformFragmentActivity;
import com.efounder.frame.baseui.BaseFragment;
import com.efounder.frame.utils.EFFrameUtils;
import com.efounder.message.struct.IMStruct002;
import com.efounder.mobilemall.R;
import com.efounder.utils.ResStringUtil;

import org.json.JSONObject;

import static com.efounder.chat.utils.HandleShareIntentUtil.SHARE_TYPE_MALL_ITEM;

/**
 * @author : zzj
 * @e-mail : zhangzhijun@pansoft.com
 * @date : 2018/9/20 17:21
 * @desc :
 * @version: 1.0
 */
public class MallPopManager {
    /**
     * 我的  和 购物车弹窗
     *
     * @param context   context
     * @param imageView 图标
     */
    public static void showMineAndCartPop(final Context context, View imageView) {

        final CommonOtherPopWindow commonOtherPopWindow = new CommonOtherPopWindow((Activity) context);
        commonOtherPopWindow.addMenuButton(context.getString(R.string.mall_pop_mine_cart), R.drawable.mall_pop_icon_cart, true)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //购物车
                        Bundle bundle = new Bundle();
                        bundle.putBoolean(EFTransformFragmentActivity.EXTRA_HIDE_TITLE_BAR, true);
                        try {
                            EFFrameUtils.pushFragment((Class<? extends BaseFragment>) Class.forName("com.efounder.fragment.MallCartFragment"), bundle);
                        } catch (ClassNotFoundException e) {
                            e.printStackTrace();
                        }
                        commonOtherPopWindow.dismiss();
                    }
                });
        commonOtherPopWindow.addMenuButton(context.getString(R.string.mall_pop_mine_mall), R.drawable.mall_pop_icon_mall)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //我的点击事件
                        try {
                            Bundle bundle = new Bundle();
                            bundle.putBoolean(EFTransformFragmentActivity.EXTRA_HIDE_TITLE_BAR, true);
                            EFFrameUtils.pushFragment((Class<? extends BaseFragment>) Class.forName("com.efounder.fragment.MyPagerFragment"),
                                    bundle);
                        } catch (ClassNotFoundException e) {
                            e.printStackTrace();
                        }
                        commonOtherPopWindow.dismiss();
                    }
                });

        commonOtherPopWindow.showPopupWindow(imageView);
    }

    /**
     * 商品分享弹窗
     *
     * @param context   context
     * @param imageView 图标
     */
    public static void showMallSharePop(final Context context, View imageView, final String goodBh,
                                        final String goodCover, final String title, final String content) {

        final CommonOtherPopWindow commonOtherPopWindow = new CommonOtherPopWindow((Activity) context);
        commonOtherPopWindow.addMenuButton(context.getString(R.string.mall_share_to_friend), R.drawable.icon_share_to_friend, true)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //购物车
                        IMStruct002 good= StructFactory.getInstance().createShareGoodsStruct(goodBh, goodCover, title, content, StructFactory.TO_USER_TYPE_OFFICIAL_ACCOUNT);
            MobileShareActivity.start(true, good, String.format(context.getResources().getString(R.string.mall_share_content_goods),title));
                        commonOtherPopWindow.dismiss();
                    }
                });
        commonOtherPopWindow.addMenuButton(context.getString(R.string.mall_share_to_zone), R.drawable.icon_share_to_zone)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //我的点击事件
                        try {
                            Intent intent = new Intent();
                            JSONObject goodObject = new JSONObject();
                            goodObject.put("goodId", goodBh);
                            goodObject.put("goodCover", goodCover);
                            goodObject.put("title", title);
                            goodObject.put("price", content);
                            goodObject.put("from", ResStringUtil.getString(R.string.mall_from));
                            goodObject.put("shopIcon", ResStringUtil.getString(com.efounder.chat.R.string.wechatview_app_icon_url));
                            ShareContent shareContent = new ShareContent();
                            shareContent.setText("");
                            shareContent.setType(SHARE_TYPE_MALL_ITEM);
                            shareContent.setGoodUrl(goodObject.toString());
                            intent.putExtra("shareContent", shareContent);
                            intent.putExtra("isLocalShare", true);
                            intent.setClass(context, ShareToZoneActivity.class);
                            context.startActivity(intent);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        commonOtherPopWindow.dismiss();
                    }
                });

        commonOtherPopWindow.showPopupWindow(imageView);
    }
}
